package com.biostime.qdingding.modules.qd.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.biostime.qdingding.common.persistence.Page;
import com.biostime.qdingding.common.utils.StringUtils;
import com.biostime.qdingding.common.web.BaseController;
import com.biostime.qdingding.modules.qd.entity.Member;
import com.biostime.qdingding.modules.qd.service.MemberService;
import com.biostime.qdingding.modules.sys.service.AreaService;
import com.biostime.qdingding.modules.sys.utils.UserUtils;

/**
 * 区域APP用户管理Controller
 * @author king
 * @version 2016-03-09
 */
@Controller
@RequestMapping(value = "${adminPath}/qd/appuser")
public class APPUserController extends BaseController {

	@Autowired
	private MemberService memberService;
	@Autowired
	private AreaService areaService;
	
	@ModelAttribute
	public Member get(@RequestParam(required=false) String id) {
		Member entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = memberService.get(new Member(id));
		}
		if (entity == null){
			entity = new Member();
		}
		return entity;
	}
	
	@RequiresPermissions("qd:appuser:view")
	@RequestMapping(value = {"list", ""})
	public String list(Member member, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Member> page = new Page<Member>(request, response);
		member.setPage(page);
		member.setCenter(UserUtils.getCenter());
		page.setList(memberService.findAPPUser(member));
		
		model.addAttribute("page", page);
		return "modules/qd/APPUserList";
	}

}